/*
 * MyParserXml.cpp
 *
 *  Created on: Feb 22, 2011
 *      Author: MongKieu
 */

#include "../inc/Utility/MyParserXml.h"
#include <FLocations.h>

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Base::Collection;
using namespace Osp::Ui::Controls;
using namespace Osp::Xml;
using namespace Osp::Io;
using namespace Osp::Media;
using namespace Osp::Graphics;
using namespace Osp::Text;
using namespace Osp::Locations;

MyParserXml::MyParserXml() {
	// TODO Auto-generated constructor stub
	pDocument = null;
	strPath = null;

}

MyParserXml::~MyParserXml() {
	// TODO Auto-generated destructor stub
}
DiaDiemKetXe::DiaDiemKetXe() {
	__pTenDiaDiem = "";
	__pLat = "";
	__pLng = "";
	__pLoaiThongTin = "";
}
DiaDiemKetXe::~DiaDiemKetXe() {
}
MyPlaceMark::MyPlaceMark() {
}
MyPlaceMark::~MyPlaceMark() {
}
MyViTriYeuThich::MyViTriYeuThich() {
	__pLat = "";
	__pLng = "";
	__pTieuDe = "";
	__pChuThich = "";
}
MyViTriYeuThich::~MyViTriYeuThich() {
}
result MyParserXml::OpenXml(char *strPath) {
	pDocument = xmlParseFile(strPath);

	if (pDocument == null) {
		AppLog("Documents not parsed successfully.");

		return E_FAILURE;
	}
	this->strPath = strPath;
	return E_SUCCESS;
}

result MyParserXml::Close(char *strPath) {
	if (pDocument != null && strPath != null) {
		xmlSaveFormatFile(strPath, pDocument, 0);
		xmlSaveFile(strPath, pDocument);
		xmlFreeDoc(pDocument);
		return E_SUCCESS;
	}
	return E_FAILURE;
}
ArrayList* MyParserXml::MoFile(char *strPath) {

	ArrayList*list = new ArrayList();
	list->Construct();

	xmlNodePtr pRoot = null;

	result r = OpenXml(strPath);
	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);

		if (pRoot == null) {
			AppLog("Error parsingXml document:%S",xmlLastError.message);
		} else {
			String studentName;
			for (xmlNodePtr pCurrentElement = pRoot->children; pCurrentElement; pCurrentElement
					= pCurrentElement->next) {


				if (pCurrentElement->type == XML_ELEMENT_NODE && pCurrentElement->children != null) {
					Osp::Base::Utility::StringUtil::Utf8ToString(
							(char*) pCurrentElement->children->content,
							studentName);
					list->Add(*(new String(studentName)));
				}
			}
			Close(strPath);
		}
	}
	return list;
}

result MyParserXml::AddNewNode(char *strPath, char* strNodeName,
		char* strNodeText) {

	OpenXml(strPath);
	if (pDocument == NULL) {
		AppLog("AddNewNode: XmlDocument is not opened.");
		return E_FAILURE;
	}
	xmlNodePtr pRoot = null;
	pRoot = xmlDocGetRootElement(pDocument);
	if (pRoot == null) {
		AppLog("AddNewNode: empty document.");
		return E_FAILURE;
	}
	xmlNewTextChild(pRoot, NULL, (xmlChar *) strNodeName,
			(xmlChar *) strNodeText);
	AppLog("vao child");
	Close(strPath);
	return true;
}

result MyParserXml::AddNewNode(char *strPath, char* strNodeName,
		String strNodeTextString) {
	char*strNodeText = GetCStringN(strNodeTextString);
	OpenXml(strPath);
	if (pDocument == NULL) {
		AppLog("AddNewNode: XmlDocument is not opened.");
		return E_FAILURE;
	}
	xmlNodePtr pRoot = null;
	pRoot = xmlDocGetRootElement(pDocument);
	if (pRoot == null) {
		AppLog("AddNewNode: empty document.");
		return E_FAILURE;
	}
	xmlNewTextChild(pRoot, NULL, (xmlChar *) strNodeName,
			(xmlChar *) strNodeText);
	AppLog("vao child");
	Close(strPath);
	AppLog("Them xong");
	return true;
}
char*
MyParserXml::GetCStringN(const String& sBadaStr) {
	if (sBadaStr.GetLength() == 0)
		return null;
	Osp::Text::AsciiEncoding ascii;
	char* chPtrBuf = null;
	int byteCount = 0;
	Osp::Base::ByteBuffer* pBuffer = ascii.GetBytesN(sBadaStr);
	if (pBuffer != null) {
		byteCount = pBuffer->GetLimit();
		chPtrBuf = new char[byteCount + 1];
		pBuffer->SetPosition(0);
		pBuffer->GetArray((byte*) chPtrBuf, 0, byteCount);
		delete pBuffer;
	}
	return chPtrBuf;
}

result MyParserXml::AddNewNodeWithArray(char *strPath, ArrayList *listName,
		ArrayList *listValue, char *nameNode) {
	OpenXml(strPath);
	if (pDocument == NULL) {
		AppLog("AddNewNode: XmlDocument is not opened.");
		return E_FAILURE;
	}
	xmlNodePtr pRoot = null;
	pRoot = xmlDocGetRootElement(pDocument);
	if (pRoot == null) {
		AppLog("AddNewNode: empty document.");
		return E_FAILURE;
	}

	//xmlNodePtr nod2e = xmlNewNode(NULL, (xmlChar*) "ViTriYeuThich");
	xmlNodePtr nod2e = xmlNewNode(NULL, (xmlChar*) nameNode);
	xmlAddChild(pRoot, nod2e);
	if (listName->GetCount() == listValue->GetCount()) {
		for (int i = 0; i < listName->GetCount(); i++) {
			char *NameNode = GetCStringN(
					(static_cast<String*> (listName->GetAt(i)))->GetPointer());
			char
					*ValueNode =
							GetCStringN(
									(static_cast<String *> (listValue->GetAt(i)))->GetPointer());
			AppLog("%s", NameNode);
			AppLog("%s", ValueNode);
			xmlNodePtr node = xmlNewTextChild(nod2e, NULL,
					(xmlChar *) NameNode, (xmlChar *) ValueNode);
			delete node;
		}
	}
	AppLog("vao child");
	Close(strPath);
	return true;
}

int MyParserXml::getViTriDuongDan(String path) {
	int result = -1;
	int lengthPath = path.GetLength();
	for (int i = lengthPath - 1; i >= 0; i--) {
		mchar k;
		path.GetCharAt(i, k);

		if (k == '/') {
			result = i;
			return result;
		}
	}
	return result;
}

MyCurrentWeather* MyParserXml::ThoiTietTrongNgay(char *strPath) {
	haveInfoWeather = false;
	AppLog("Vao hàm parser th?i ti?t");
	result r = OpenXml(strPath);
	MyCurrentWeather*curWeather = new MyCurrentWeather();
	if (IsFailed(r) == true) {
		AppLog("Lay thoi tiet that bai");
	} else {
		xmlNodePtr pRoot = xmlDocGetRootElement(pDocument);
		for (xmlNodePtr pCurrentElement = pRoot->children; pCurrentElement; pCurrentElement
				= pCurrentElement->next) {
			if (xmlStrcmp(pCurrentElement->name, (const xmlChar*) "weather")
					== false) {
				for (xmlNodePtr pChildInfoWeather = pCurrentElement->children; pChildInfoWeather; pChildInfoWeather
						= pChildInfoWeather->next) {
					/* Vao forecast_information*/
					if (xmlStrcmp(pChildInfoWeather->name,
							(const xmlChar*) "forecast_information") == false) {
						for (xmlNodePtr pChildCondition =
								pChildInfoWeather->children; pChildCondition; pChildCondition
								= pChildCondition->next) {
							xmlChar *uri = xmlGetProp(pChildCondition,
									(const xmlChar*) "data");
							if (xmlStrcmp(pChildCondition->name,
									(const xmlChar*) "postal_code") == false) {
								Utility::StringUtil::Utf8ToString((char*) uri,
										curWeather->__myAddress);
								haveInfoWeather = true;
								xmlFree(uri);
							}
							if (xmlStrcmp(pChildCondition->name,
									(const xmlChar*) "current_date_time")
									== false) {
								Utility::StringUtil::Utf8ToString((char*) uri,
										curWeather->__myTimeCurrent);
								xmlFree(uri);
							}
						}
					}
					/* Vao current_conditions*/
					if (xmlStrcmp(pChildInfoWeather->name,
							(const xmlChar*) "current_conditions") == false) {
						for (xmlNodePtr pChildCondition =
								pChildInfoWeather->children; pChildCondition; pChildCondition
								= pChildCondition->next) {
							//String strValue;
							xmlChar *uri = xmlGetProp(pChildCondition,
									(const xmlChar*) "data");
							if (xmlStrcmp(pChildCondition->name,
									(const xmlChar*) "condition") == false) {
								String str, strValue;
								Utility::StringUtil::Utf8ToString((char*) uri,
										strValue);
								str.Format(500, L"Condition:%S",strValue.GetPointer());
								curWeather->__myConditionCur=str;
								xmlFree(uri);
							}
							if (xmlStrcmp(pChildCondition->name,
											(const xmlChar*) "temp_f") ==false)
							{
								String str, strValue;
								Utility::StringUtil::Utf8ToString((char*) uri,strValue);
								str.Format(500,L"Temp:%S F",strValue.GetPointer());
								curWeather->__myTemp_fCur=str;
								xmlFree(uri);
							}
							if (xmlStrcmp(pChildCondition->name,(const xmlChar*) "temp_c") == false) {
									String str, strValue;
							Utility::StringUtil::Utf8ToString((char*) uri,strValue);
							str.Format(500,L"Temp C: %S C",strValue.GetPointer());
							curWeather->__myTemp_cCur=str;
							xmlFree(uri);
						}
							if (xmlStrcmp(pChildCondition->name,(const xmlChar*) "icon") == false) {
								Utility::StringUtil::Utf8ToString((char*) uri,curWeather->__myIconCur);
								int indexDuongDan=getViTriDuongDan(curWeather->__myIconCur);
								if(indexDuongDan>=0)
								{
									curWeather->__myIconCur.SubString(indexDuongDan+1, curWeather->__myIconCur);
								}
							xmlFree(uri);
							}
							if (xmlStrcmp(pChildCondition->name,(const xmlChar*) "wind_condition") == false) {
								Utility::StringUtil::Utf8ToString((char*) uri,curWeather->__myWindCur);
								xmlFree(uri);
							}
							else if (xmlStrcmp(pChildCondition->name,(const xmlChar*) "humidity") == false) {
								Utility::StringUtil::Utf8ToString((char*) uri,curWeather->__myHumidityCur);
								xmlFree(uri);
								}
						}

							}
						}
					}
				}
			}
	Close(strPath);
			return curWeather;
		}
LinkedListT<MyCurrentWeather*> *MyParserXml::ThoiTietDuBaoTrongTuan(
		char*strPath) {
	LinkedListT<MyCurrentWeather*>*list = new LinkedListT<MyCurrentWeather*> ();
	xmlNodePtr pRoot = null;
	result r = OpenXml(strPath);
	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);
		if (pRoot == null) {
			AppLog("Error parsingXml document:%S",xmlLastError.message);
		} else {
			for (xmlNodePtr pCurrentElement = pRoot->children; pCurrentElement; pCurrentElement
					= pCurrentElement->next) {
				if (xmlStrcmp(pCurrentElement->name, (const xmlChar*) "weather")
						== false) {
					for (xmlNodePtr pChildInfoWeather =
							pCurrentElement->children; pChildInfoWeather; pChildInfoWeather
							= pChildInfoWeather->next) {
						/* Vao current_conditions*/
						if (xmlStrcmp(pChildInfoWeather->name,
								(const xmlChar*) "forecast_conditions")
								== false) {
							MyCurrentWeather*curWeather =
									new MyCurrentWeather();
							for (xmlNodePtr pChildCondition =
									pChildInfoWeather->children; pChildCondition; pChildCondition
									= pChildCondition->next) {
								//String strValue;
								xmlChar *uri = xmlGetProp(pChildCondition,
										(const xmlChar*) "data");
								if (xmlStrcmp(pChildCondition->name,
										(const xmlChar*) "day_of_week")
										== false) {
									Utility::StringUtil::Utf8ToString(
											(char*) uri,
											curWeather->__myAddress);
									xmlFree(uri);
								}
								if (xmlStrcmp(pChildCondition->name,
										(const xmlChar*) "low") == false) {
									Utility::StringUtil::Utf8ToString(
											(char*) uri,
											curWeather->__myTemp_fCur);
									xmlFree(uri);
								}
								if (xmlStrcmp(pChildCondition->name,
										(const xmlChar*) "high") == false) {
									Utility::StringUtil::Utf8ToString(
											(char*) uri,
											curWeather->__myTemp_cCur);
									xmlFree(uri);
								}
								if (xmlStrcmp(pChildCondition->name,
										(const xmlChar*) "icon") == false) {
									Utility::StringUtil::Utf8ToString(
											(char*) uri,
											curWeather->__myIconCur);
									int indexDuongDan = getViTriDuongDan(
											curWeather->__myIconCur);
									if (indexDuongDan >= 0) {
										curWeather->__myIconCur.SubString(
												indexDuongDan + 1,
												curWeather->__myIconCur);
									}
									xmlFree(uri);
								}
								if (xmlStrcmp(pChildCondition->name,
										(const xmlChar*) "condition") == false) {
									Utility::StringUtil::Utf8ToString(
											(char*) uri,
											curWeather->__myConditionCur);
									xmlFree(uri);
								}
							}
							list->Add(curWeather);
						}
					}
				}
			}
		}
	}
	Close(strPath);
	return list;

}
Bitmap* MyParserXml::LoadImageN(String FileName) {
	result r = E_SUCCESS;

	Image* pImage = new Image();
	r = pImage->Construct();

	Bitmap* pBitmap = null;
	pBitmap = pImage->DecodeN(FileName, BITMAP_PIXEL_FORMAT_RGB565);

	return pBitmap;

}
bool MyParserXml::checkHaveInfoWeather() {
	return haveInfoWeather;
}

LinkedListT<DiaChi>* MyParserXml::layGiaTriVaoMangPlaceMarkN(char * giatri) {
	LinkedListT<DiaChi> *lst = new LinkedListT<DiaChi> ();

	xmlNodePtr pRoot = null;

	result r = OpenXml(giatri);
	String ketQua;
	String temp = L"";
	String strLng = L"";
	String strLat = L"";
	float lng = 0.0;
	float lat = 0.0;

	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);
		if (pRoot == null) {
			AppLog("Error parsingXml document:%S",xmlLastError.message);
		} else {
			for (xmlNodePtr pCurrentElement = pRoot->children;pCurrentElement; pCurrentElement
					= pCurrentElement->next) {
				if (xmlStrcmp(pCurrentElement->name,
								(const xmlChar*) "Document") == false) {
					AppLog("Vao document");
					for (xmlNodePtr pchildDocument = pCurrentElement->children; pchildDocument; pchildDocument
							= pchildDocument->next) {
						if (xmlStrcmp(pchildDocument->name,
										(const xmlChar*) "Placemark") == false) {
							DiaChi diaChi;
							for (xmlNodePtr pChildPlaceMark =
									pchildDocument->children; pChildPlaceMark; pChildPlaceMark
									= pChildPlaceMark->next) {
								if (xmlStrcmp(pChildPlaceMark->name,
												(const xmlChar*) "name") == false) {
									Osp::Base::Utility::StringUtil::Utf8ToString(
											(char*) pChildPlaceMark->children->content,
											diaChi.tenDiaDiem);
									AppLog("Vao address");
								}
								if (xmlStrcmp(pChildPlaceMark->name,
												(const xmlChar*) "Point") == false) {
									for (xmlNodePtr pChilePoint =
											pChildPlaceMark->children; pChilePoint; pChilePoint
											= pChilePoint->next) {
										if (xmlStrcmp(pChilePoint->name,
														(const xmlChar*) "coordinates")
												== false) {
											Osp::Base::Utility::StringUtil::Utf8ToString(
													(char*) pChilePoint->children->content,
													temp);
											int index;
											int index2;
											temp.IndexOf(',', 0, index);
											temp.IndexOf(',', index + 1, index2);
											temp.SubString(0, index, strLat);
											index ++;
											index2 -= index;
											temp.SubString(index, index2, strLng);

											Float::Parse(strLng, lng);
											Float::Parse(strLat, lat);

											diaChi.toaDo.lat = lat;
											diaChi.toaDo.lng = lng;
											AppLog("Vao point");
										}
									}
								}
							}
							lst->Add(diaChi);
						}
					}

				}
			}

		}
	}
	Close(strPath);

	return lst;
	/*
	 * 	MyParserXml *myPa = new MyParserXml();

	 LinkedListT<MyPlaceMark*>*list = new LinkedListT<MyPlaceMark*> ();
	 list = myPa->layGiaTriVaoMangPlaceMark("/Home/FileKML.xml");
	 AppLog("Xuat ket qua ra man hinh tu list");
	 for (int i = 0; i < list->GetCount(); i++) {
	 MyPlaceMark*p = new MyPlaceMark();
	 list->GetAt(i, p);
	 AppLog("--Address:%S", p->__pAddress.GetPointer());
	 AppLog("--Coordin:%S", p->__pCoordinates.GetPointer());
	 }
	 *
	 * */

}
LinkedListT<MyViTriYeuThich*>*MyParserXml::getLayMangViTriYeuThich(
		char * strPath) {
	LinkedListT<MyViTriYeuThich*>*list = new LinkedListT<MyViTriYeuThich*> ();

	xmlNodePtr pRoot = null;
	result r = OpenXml(strPath);
	String ketQua;
	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);// Mang MangViTriYeuThich
		if (pRoot == null) {
			AppLog("Error parsingXml document:%S",xmlLastError.message);
		} else {
			for (xmlNodePtr pCurrentViTri = pRoot->children; pCurrentViTri; pCurrentViTri
					= pCurrentViTri->next) {
				if (xmlStrcmp(pCurrentViTri->name,
						(const xmlChar*) "ViTriYeuThich") == false) {
					AppLog("ViTriYeuThich");
					MyViTriYeuThich *pViTriYeuThich = new MyViTriYeuThich();
					for (xmlNodePtr pChildElement = pCurrentViTri->children; pChildElement; pChildElement
							= pChildElement->next) {
						if (xmlStrcmp(pChildElement->name,
								(const xmlChar*) "Lat") == false) {
							Osp::Base::Utility::StringUtil::Utf8ToString(
									(char*) pChildElement->children->content,
									pViTriYeuThich ->__pLat);
							AppLog("Vao Lat");
						}
						if (xmlStrcmp(pChildElement->name,
								(const xmlChar*) "Lng") == false) {
							Osp::Base::Utility::StringUtil::Utf8ToString(
									(char*) pChildElement->children->content,
									pViTriYeuThich ->__pLng);
							AppLog("Vao Lng");
						}
						if (xmlStrcmp(pChildElement->name,
								(const xmlChar*) "TieuDe") == false) {
							Osp::Base::Utility::StringUtil::Utf8ToString(
									(char*) pChildElement->children->content,
									pViTriYeuThich ->__pTieuDe);
							AppLog("Vao TieuDe");
						}
						if (xmlStrcmp(pChildElement->name,
								(const xmlChar*) "ChuThich") == false) {
							Osp::Base::Utility::StringUtil::Utf8ToString(
									(char*) pChildElement->children->content,
									pViTriYeuThich ->__pChuThich);
							AppLog("Vao ChuThich");
						}
					}
					list->Add(pViTriYeuThich);
				}
			}

		}
	}
	Close(strPath);
	return list;
}
LinkedListT<DiaDiemKetXe*>*MyParserXml::getLayMangDiaDiemKetXe(char*strPath) {
	LinkedListT<DiaDiemKetXe*>*list = new LinkedListT<DiaDiemKetXe*> ();
	xmlNodePtr pRoot = null;
	result r = OpenXml(strPath);
	String ketQua;
	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);
		if (IsFailed(r) == true) {
			AppLog("Loi parsing Xml document:%S", xmlLastError.message);
		} else if(pRoot->children!=null){
			for (xmlNodePtr nodeDiaDiem = pRoot->children; nodeDiaDiem; nodeDiaDiem
					= nodeDiaDiem->next) {
				if (nodeDiaDiem->type == XML_ELEMENT_NODE) {
					DiaDiemKetXe *diaDiemKetXe = new DiaDiemKetXe();
					xmlChar *mytenDiaDiem = xmlGetProp(nodeDiaDiem,
							(const xmlChar*) "tenDiaDiem");
					Utility::StringUtil::Utf8ToString((char*) mytenDiaDiem,
							diaDiemKetXe->__pTenDiaDiem);
					xmlChar *myLat = xmlGetProp(nodeDiaDiem,
							(const xmlChar*) "Lat");
					Utility::StringUtil::Utf8ToString((char*) myLat,
							diaDiemKetXe->__pLat);
					xmlChar*myLng = xmlGetProp(nodeDiaDiem,
							(const xmlChar*) "Lng");
					Utility::StringUtil::Utf8ToString((char*) myLng,
							diaDiemKetXe->__pLng);
					xmlChar*myLoaiThongTin = xmlGetProp(nodeDiaDiem,
							(const xmlChar*) "loaiThongTin");
					Utility::StringUtil::Utf8ToString((char*) myLoaiThongTin,
							diaDiemKetXe->__pLoaiThongTin);
					list->Add(diaDiemKetXe);
				}
			}
		}
	}
	Close(strPath);
	return list;
}
bool MyParserXml::xoaNodeInXml(char*strPath, String myLat, String myLng) {
	xmlNodePtr pRoot = null;
	result r = OpenXml(strPath);
	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);// Mang MangViTriYeuThich
		if (pRoot == null) {
			AppLog("Error parsingXml document:%S",xmlLastError.message);
		} else {
			for (xmlNodePtr pCurrentViTri = pRoot->children; pCurrentViTri; pCurrentViTri
					= pCurrentViTri->next) {
				if (xmlStrcmp(pCurrentViTri->name,
						(const xmlChar*) "ViTriYeuThich") == false) {

					MyViTriYeuThich *pViTriYeuThich = new MyViTriYeuThich();

					for (xmlNodePtr pChildElement = pCurrentViTri->children; pChildElement; pChildElement
							= pChildElement->next) {
						if (xmlStrcmp(pChildElement->name,
								(const xmlChar*) "Lat") == false) {
							Osp::Base::Utility::StringUtil::Utf8ToString(
									(char*) pChildElement->children->content,
									pViTriYeuThich ->__pLat);
							AppLog("Vao Lat");
						}
						if (xmlStrcmp(pChildElement->name,
								(const xmlChar*) "Lng") == false) {
							Osp::Base::Utility::StringUtil::Utf8ToString(
									(char*) pChildElement->children->content,
									pViTriYeuThich ->__pLng);
							AppLog("Vao Lng");
						}
					}
					/*Xac dinh id can xoa*/
					if (pViTriYeuThich->__pLat.Equals(myLat) == true
							&& pViTriYeuThich->__pLng.Equals(myLng) == true) {
						xmlUnlinkNode(pCurrentViTri);
						Close(strPath);
						return true;
					}
				}
			}

		}
	}

	Close(strPath);
	return false;
}

LinkedListT<DiaChi>* MyParserXml::getLayMangDiaChiBangTenDiaDiemHoacToaDo(
		char * giatri) {
	LinkedListT<DiaChi> *lst = new LinkedListT<DiaChi> ();
	xmlNodePtr pRoot = null;
	result r = OpenXml(giatri);
	String ketQua;
	String temp = L"";
	String strLng = L"";
	String strLat = L"";
	float lng = 0.0;
	float lat = 0.0;
	if (IsFailed(r) == true) {
		AppLog("Viec mo file that bai");
	} else {
		pRoot = xmlDocGetRootElement(pDocument);
		if (pRoot == null) {
			AppLog("Error parsingXml document:%S",xmlLastError.message);
		} else {
			for (xmlNodePtr pCurrentElement = pRoot->children;pCurrentElement; pCurrentElement
					= pCurrentElement->next) {
				if (xmlStrcmp(pCurrentElement->name,
								(const xmlChar*) "Response") == false) {
					AppLog("Vao document");
					for (xmlNodePtr pchildDocument = pCurrentElement->children; pchildDocument; pchildDocument
							= pchildDocument->next) {
						if (xmlStrcmp(pchildDocument->name,
										(const xmlChar*) "Placemark") == false) {
							DiaChi diaChi;
							for (xmlNodePtr pChildPlaceMark =
									pchildDocument->children; pChildPlaceMark; pChildPlaceMark
									= pChildPlaceMark->next) {
								if (xmlStrcmp(pChildPlaceMark->name,
												(const xmlChar*) "address") == false) {
									String add;
									Osp::Base::Utility::StringUtil::Utf8ToString(
											(char*) pChildPlaceMark->children->content,
											diaChi.tenDiaDiem);

									AppLog("Vao address:%S", diaChi.tenDiaDiem.GetPointer());
								}
								if (xmlStrcmp(pChildPlaceMark->name,
												(const xmlChar*) "Point") == false) {
									for (xmlNodePtr pChilePoint =
											pChildPlaceMark->children; pChilePoint; pChilePoint
											= pChilePoint->next) {
										if (xmlStrcmp(pChilePoint->name,
														(const xmlChar*) "coordinates")
												== false) {
											Osp::Base::Utility::StringUtil::Utf8ToString(
													(char*) pChilePoint->children->content,
													temp);
											int index;
											int index2;
											temp.IndexOf(',', 0, index);
											temp.IndexOf(',', index + 1, index2);
											temp.SubString(0, index, strLat);
											index ++;
											index2 -= index;
											temp.SubString(index, index2, strLng);

											Float::Parse(strLng, lat);
											Float::Parse(strLat, lng);

											diaChi.toaDo.lat = lat;
											diaChi.toaDo.lng = lng;
											AppLog("Vao point");
										}
									}
								}
							}
							lst->Add(diaChi);
						}
					}

				}
			}

		}
	}
	Close(strPath);
	 for (int i = 0; i < lst->GetCount(); i++) {
		 DiaChi p ;
		 lst->GetAt(i, p);
		 AppLog("-----------Address:%S", p.tenDiaDiem.GetPointer());
		 AppLog("--Coor Lat:%f", p.toaDo.lat);

		 }
	return lst;
	/*
	 * 	MyParserXml *myPa = new MyParserXml();

	 LinkedListT<MyPlaceMark*>*list = new LinkedListT<MyPlaceMark*> ();
	 list = myPa->layGiaTriVaoMangPlaceMark("/Home/FileKML.xml");
	 AppLog("Xuat ket qua ra man hinh tu list");
	 for (int i = 0; i < list->GetCount(); i++) {
	 MyPlaceMark*p = new MyPlaceMark();
	 list->GetAt(i, p);
	 AppLog("--Address:%S", p->__pAddress.GetPointer());
	 AppLog("--Coordin:%S", p->__pCoordinates.GetPointer());
	 }
	 *
	 * */

}
